package com.zh.test.config;

import com.zh.test.bean.OutJson;
import com.zh.test.exception.NotFoundInventoryException;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

@RestControllerAdvice
public class ExceptionProcessor {
    @ResponseBody
    @ExceptionHandler(value = {NotFoundInventoryException.class})
    public OutJson NotFoundInventoryExceptionHandler(NotFoundInventoryException exp){

        if(exp.errorEnum.code() == 400){
           return new OutJson().setMessage(exp.getMessage());
        }
        return new OutJson().setMessage(exp.getMessage());
    }
    /**
     * @describe 拦截全局异常
     * @author zh
     * @date 2021/9/10 11:42
     * @param
     * @return com.zh.test.bean.OutJson
     */
    @ResponseBody
    @ExceptionHandler(value = {Exception.class})
    public OutJson ExceptionHandler(Exception exp){


        return new OutJson().setMessage(exp.getMessage());
    }

    /**
     * @describe 注册全局的参数转换器
     * @author zh
     * @date 2021/9/10 11:43
     * @param
     * @return void
     */
    @InitBinder
    public void registerCustomEditor(WebDataBinder binder){


    }
}
